There are several methods to read or write object properties using the server object directly. The most common and recommended method is described below.
The AMDocumentRepository object implements the LoadPropertyValues method. The following code sample demonstrates how to read a set of property values using this method.
Dim PropertyValues As Variant
Dim PropertySet As AMPropertySet
Dim PropertyDefs As AMTableViewCollection
' First we need a collection of the properties that we are interested in
' This can be a property set....
Set PropertySet = dr.Environment.PropertySets.Item("Custom")
If Not PropertySet Is Nothing Then
Set PropertyDefs = PropertySet.PropertyDefs
' Now we get an array with the property values for all properties in "Custom"
PropertyValues = dr.LoadPropertyValuesEx(Document, PropertySet, eFailIfPDNotFound)
End If
Dim Company As Variant
Dim ProjectNumber As Variant
Dim Author As Variant
' In the array of values we need to find the property we need
If IsArray(PropertyValues) Then
' We need to calculate the index of the property in the propertyset
Company = PropertyValues(PropertyDefs.Index("Company"))
ProjectNumber = PropertyValues(PropertyDefs.Index("ProjectNumber"))
Author = PropertyValues(PropertyDefs.Index("Author"))
End If
The next code shows how to save changed property values back to the vault.
PropertyValues(PropertyDefs.Index("Company")) = "New Company"
PropertyValues(PropertyDefs.Index("ProjectNumber")) = "Next Project"
PropertyValues(PropertyDefs.Index("Author")) = dr.User
dr.SavePropertyValues Document, PropertySet, PropertyValues
The LoadPropertyValuesEx method is similar to LoadPropertyValues. But it can take string parameters to define the required properties. The code below shows how this can be used to retrieve property values.
Dim PropertyNames(2) As String
Dim PropertyValues As Variant
' We can use an array of property descriptors to define the properties that we are interested in
PropertyNames(0) = "Custom.Company"
PropertyNames(1) = "Custom.ProjectNumber"
PropertyNames(2) = "Custom.Author"
' Now we get an array with the property values for the selected properties
PropertyValues = dr.LoadPropertyValuesEx(Document, PropertyNames, eFailIfPDNotFound)
Dim Company As Variant
Dim ProjectNumber As Variant
Dim Author As Variant
' In the array of values we need to find the property values
If IsArray(PropertyValues) Then
' The indexes of the properties are the same as in 'PropertyNames'
Company = PropertyValues(0)
ProjectNumber = PropertyValues(1)
Author = PropertyValues(2)
' To change a value we call SavePropertyValuesEx
PropertyValues(0) = "New Company"
Call dr.SavePropertyValuesEx( Document, PropertyNames, eFailIfPDNotFound, PropertyValues)
End If
Related information
Using a tableview
Using the LoadProperties method